<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>后台系统</title>
		<link rel="stylesheet" type="text/css" href="../css/bootstrap.min.css" />
		<link rel="stylesheet" href="./css/index.min.css">
		<script src="../js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../js/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../js/my_connect.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			//为登陆用户 直接返回首页
			let user = localStorage.getItem("user");
			if (!user) {
				//没有user的值
				alert("为登陆的用户不可以访问后台！");
				location.href = "../login.html";
			}
			//如果有人 手动改写了 user的值 就需要用户校验
			//向服务器发送数据 校验用户 （用tell和token）
			async function ck() {
				let tell = localStorage.getItem("tell");
				let token = localStorage.getItem("token");
				let res = await ($$.checkUser({
					tell,
					token
				}));
				console.log(res);
				if (!res.status) {
					//非法用户
					alert("非法的用户不可以访问后台！");
					location.href = "../login.html";
				}
			}
			ck();
		</script>
	</head>
	<body>
		<header>
			<nav class="navbar navbar-default navbar-fixed-top">
				<div class="container">
					<!--小屏幕导航按钮和logo-->
					<div class="navbar-header">
						<button class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
							<span class="icon-bar"></span>
							<span class="icon-bar"></span>
							<span class="icon-bar"></span>
						</button>
						<a href="../index.html" class="navbar-brand">HPIT后台</a>
					</div>
					<!--小屏幕导航按钮和logo-->
					<!--导航-->
					<div class="navbar-collapse collapse">
						<ul class="nav navbar-nav navbar-right">
							<li><a id="user" href="javaScript:void(0)">用户名</a></li>
							<li><a id="tuichu" href="javaScript:void(0)">退出</a></li>
						</ul>
					</div>
					<!--导航-->
				</div>
			</nav>
		</header>
		<section id="admin">
			<div class="container-fluid">
				<div class="row">
					<div class="col-md-2">
						<div class="list-group">
							<a href="javascript:void(0)" class="list-group-item active" data-href="static.html">数据统计</a>
							<a href="javascript:void(0)" class="list-group-item" data-href="article.html">文章管理</a>
							<a href="javascript:void(0)" class="list-group-item" data-href="comment.html">评论管理</a>
						</div>
					</div>
					<div class="col-md-10">
						<iframe class="col-md-12" src="./part/static.html" frameborder="0"></iframe>
					</div>
				</div>
			</div>
		</section>
		<script type="text/javascript">
			$(function() {
				let user = localStorage.getItem("user");
				$("#user").text(user);
				$("#tuichu").click(function() {
					if (confirm("确定要退出登陆吗？")) {
						localStorage.removeItem("user");
						localStorage.removeItem("tell");
						localStorage.removeItem("token");
						location.href = "../index.html"
					}
				})

				//点击事件 切换iframe
				$("a.list-group-item").click(function() {
					let href = $(this).attr("data-href")
					$("iframe").attr("src",`./part/${href}`);
					$(this).addClass("active").siblings().removeClass("active");
				})
			})
		</script>
	</body>
</html>
